package com.xintonghua.base.ui;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hao on 2017/2/6.
 */

public abstract class RecyclerViewAdapterBase<T, V extends View> extends RecyclerView.Adapter<ViewWrapper<V>> {
    protected onRecyclerViewItemClickListener itemClickListener = null;

    /**
     * 存储需要绑定的数据
     */
    protected List<T> items = new ArrayList<T>();

    public List<T> getItems() {
        return items;
    }


    public void setItems(List<T> items) {
        this.items = items;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return items.size();
    }

    /**
     * 进行创建视图承载类
     *
     * @param parent
     * @param viewType
     * @return
     */
    @Override
    public final ViewWrapper<V> onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewWrapper<V>(onCreateItemView(parent, viewType));
    }

    /**
     * 创建视图Item，交给具体实现类完成
     *
     * @param parent
     * @param viewType
     * @return
     */
    protected abstract V onCreateItemView(ViewGroup parent, int viewType);


    public interface onRecyclerViewItemClickListener {

        void onItemClick(View v, int position);
    }

    public void setOnItemClickListener(onRecyclerViewItemClickListener listener) {
        this.itemClickListener = listener;
    }

}
